#define LEDPIN A0
int i = 0;
int inChar = 0;

void setup() {
  // initialize serial:
  Serial.begin(9600);
  // reserve 200 bytes for the inputString:
  pinMode(LEDPIN, OUTPUT);  
}

void loop() {
  // print the string when a newline arrives:

}

void serialEvent() {
  while (Serial.available()) {
    i = (i+1)%4;
    inChar = (int)Serial.read();
    if(i == 3)
    switch(inChar){
      case 2:
      Serial.println("on");
      digitalWrite(LEDPIN, HIGH);
      break;
      case 3:
      Serial.println("off");
      digitalWrite(LEDPIN, LOW);
      break;
    }
    Serial.println(inChar);
   }
}
